#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>

using namespace std;

vector<int> TwoSum(vector<int>& nums, int target) {
	sort(nums.begin(), nums.end());
	vector<int> ret;
	int left = 0, right = nums.size() - 1;
	while (left < right) {
		if (nums[left] + nums[right] > target)
			--right;
		else if (nums[left] + nums[right] < target)
			++left;
		else {
			ret.push_back(nums[left]);
			ret.push_back(nums[right]);
			break;
		}
	}
	return ret;
}

void test_1() {
	vector<int> v1{ 15,11,7,2 };
	vector<int> v2{ 10,30,26,47,31,60 };
	vector<int> v3{ 2,7 };
	vector<int> v4{ 10,30 };
	assert(TwoSum(v1, 9) == v3);
	assert(TwoSum(v2, 40) == v4);
}

int main() {
	test_1();
	return 0;
}